import React, { useEffect } from "react";
import { Form, Input } from "antd";

const AddUpdateForm = ({ formRef, categoryName }) => {
  const [form] = Form.useForm();

  useEffect(() => {
    form.setFieldsValue({
      categoryName: categoryName || "",
    });
  }, [categoryName, form]);

  return (
    <Form form={form} ref={formRef}>
      <Form.Item
        name="categoryName"
        initialValue={categoryName}
        rules={[{ required: true, message: "分类名称必须输入" }]}
      >
        <Input placeholder="请输入分类名称" />
      </Form.Item>
    </Form>
  );
};

export default AddUpdateForm;
